<template>
  <div class="situation-statistics">
    <nanning-screen-border-box :bgImg="bgImg">
      <screen-title>态势统计</screen-title>
      <div class="situation-statistics-content">
        <div class="statistics-item" v-for="(item, index) in statisticsList" :key="index" :style="{background: `url(${item.bg}) no-repeat`, backgroundSize: '100% 100%'}">
          <div class="num">{{item.value}}</div>
          <div class="tip">{{item.label}}</div>
        </div>
      </div>
    </nanning-screen-border-box>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { numAnimation } from 'utils/common'
import { getSituationStatistics } from 'api/situationAwareness/busWay/screenCenter'
@Component({
  name: 'situation-statistics'
})

export default class SituationStatistics extends Vue {
  private bgImg: string = require('assets/images/situational-awareness/bus-way-left-bg.png')

  private statisticsList = [
    { bg: require('assets/images/situational-awareness/bus-way-bg.png'), label: '公交线路', value: 0 },
    { bg: require('assets/images/situational-awareness/actual-online-bus-bg.png'), label: '实时上线车辆', value: 0 }
  ]

  created() {
    this.getSituationStatistics()
  }

  // 获取态势统计
  private async getSituationStatistics () {
    try {
      const res: any = await getSituationStatistics()
      const { busNum, routeNum } = res.data
      numAnimation(this.statisticsList[0].value, parseInt(routeNum) || 0, this.statisticsList[0], 'value')
      numAnimation(this.statisticsList[1].value, parseInt(busNum) || 0, this.statisticsList[1], 'value')
      console.log('公交线路-态势统计', res)
    } catch (err) {
      console.error('公交线路-态势统计', err)
    }
  }
}
</script>

<style lang="scss" scoped>
.situation-statistics {
  width: 100%;
  height: 48%;
  /deep/ .nanning-screen-border-box {
    background-size: 100% 101% !important;
  }
  &-content {
    width: 100%;
    height: calc(100% - 50px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .statistics-item {
      width: 418px;
      height: 124px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      box-sizing: border-box;
      padding-left: 190px;
      position: relative;
      &::before {
        content: '';
        position: absolute;
        width: 1px;
        height: 50px;
        top: 37px;
        left: 170px;
        background: linear-gradient(to bottom, #0c2b68, #3970a5, #0c2b68);
      }
      .num {
        font-size: 30px;
        line-height: 44px;
        font-family: 'PingFang Regular';
        font-weight: bold;
        color: #fff;
      }
      .tip {
        font-size: 14px;
        line-height: 28px;
        font-family: 'PingFang Regular';
        font-weight: 400;
        color: rgba(255, 255, 255, 0.76);
      }
      & + .statistics-item {
        margin-top: 3%;
      }
    }
  }
}
</style>
